package com.ywd.materials.admin.controller;

import com.ywd.materials.admin.common.Common;
import com.ywd.materials.admin.dto.AdminRoleDto;
import com.ywd.materials.admin.dto.AdminRoleMenuDto;
import com.ywd.materials.admin.dto.query.AdminRoleQuery;
import com.ywd.materials.admin.exception.R;
import com.ywd.materials.admin.exception.RPage;
import com.ywd.materials.admin.service.impl.AdminMenuServiceImpl;
import com.ywd.materials.admin.service.impl.AdminRoleServiceImpl;
import com.ywd.materials.admin.vo.AdminRoleDetailsVo;
import com.ywd.materials.admin.vo.AdminRoleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lk
 * @date 2024/4/17 13:53
 */
@AllArgsConstructor
@RestController
@RequestMapping("/adminRole")
@Tag(name = "角色管理")
public class AdminRoleController {

    private final AdminRoleServiceImpl adminRoleServiceImpl;
    private final AdminMenuServiceImpl adminMenuServiceImpl;

    @PostMapping("/getRolePage")
    @Operation(summary = "角色列表(分页)")
    public R<RPage<List<AdminRoleVo>>> getRolePage(@RequestBody AdminRoleQuery query) {
        return R.ok(adminRoleServiceImpl.getRolePage(query));
    }

    /**
     * 查询角色详情
     */
    @GetMapping("/getRoleDetails")
    @Operation(summary = "查询角色详情")
    public R<AdminRoleDetailsVo> getRoleDetails(@Schema(description = "角色ID") @RequestParam("id") Long id){
        return R.ok(adminRoleServiceImpl.getRoleDetails(id));
    }

    @PostMapping("/addRole")
    @Operation(summary = "新增角色")
    public R<Boolean> addRole(@RequestBody AdminRoleDto dto) {
        return R.ok(adminRoleServiceImpl.addRole(dto));
    }

    @PutMapping("/updateRole")
    @Operation(summary = "修改角色")
    public R<Boolean> updateRole(@RequestBody AdminRoleDto dto) {
        return R.ok(adminRoleServiceImpl.updateRole(dto));
    }

    @DeleteMapping("/deleteRole")
    @Operation(summary = "删除角色")
    public R<Boolean> deleteRole(@Schema(description = "角色ID") @RequestParam Long id) {
        return R.ok(adminRoleServiceImpl.deleteRole(id));
    }

    @GetMapping("/getRolePartList")
    @Operation(summary = "角色列表(筛选项)")
    public R<List<Common>> getRolePartList(@Schema(description = "名称") @RequestParam(required = false) String name) {
        return R.ok(adminRoleServiceImpl.getRolePartList(name));
    }

    @GetMapping("/getMenuPartList")
    @Operation(summary = "菜单列表(筛选项)")
    public R<List<Common>> getMenuPartList(@Schema(description = "名称") @RequestParam(required = false) String name) {
        return R.ok(adminMenuServiceImpl.getMenuPartList(name));
    }

    @PostMapping("/addRoleMenu")
    @Operation(summary = "为角色分配菜单")
    public R<Boolean> addRoleMenu(@RequestBody AdminRoleMenuDto dto) {
        return R.ok(adminRoleServiceImpl.addRoleMenu(dto));
    }


}
